<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/Liang34/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/Liang34/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/Liang34/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/Liang34/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/Liang34/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/Liang34/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/Liang34/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="选择排序（不稳定算法）思想：选择排序，从头至尾扫描序列，找出最小的一个元素，和第一个元素交换，接着从剩下的元素中继续这种选择和交换方式，最终得到一个有序序列。 实例：[12,45,40,24,15,11,12,11]，初始数组内均为有序区第一趟遍历：[{11},40,24,15,45,12]，花扩号内为无序区第二趟遍历：[{11,12},24,15,45,40]第三趟遍历: [{11,12,15}">
<meta property="og:type" content="article">
<meta property="og:title" content="selectOrder">
<meta property="og:url" content="https://liang34.github.io/Liang34/2020/03/02/selectOrder/index.html">
<meta property="og:site_name" content="liang34">
<meta property="og:description" content="选择排序（不稳定算法）思想：选择排序，从头至尾扫描序列，找出最小的一个元素，和第一个元素交换，接着从剩下的元素中继续这种选择和交换方式，最终得到一个有序序列。 实例：[12,45,40,24,15,11,12,11]，初始数组内均为有序区第一趟遍历：[{11},40,24,15,45,12]，花扩号内为无序区第二趟遍历：[{11,12},24,15,45,40]第三趟遍历: [{11,12,15}">
<meta property="article:published_time" content="2020-03-02T09:33:16.000Z">
<meta property="article:modified_time" content="2020-03-02T13:12:50.671Z">
<meta property="article:author" content="LiangJH">
<meta name="twitter:card" content="summary">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/Liang34/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://liang34.github.io/Liang34/2020/03/02/selectOrder/"/>





  <title>selectOrder | liang34</title>
  








<meta name="generator" content="Hexo 4.2.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/Liang34/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">liang34</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/Liang34/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/Liang34/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/Liang34/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/Liang34/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://liang34.github.io/Liang34/Liang34/2020/03/02/selectOrder/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="LiangJH">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/Liang34/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="liang34">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">selectOrder</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-03-02T17:33:16+08:00">
                2020-03-02
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/Liang34/categories/%E7%AE%97%E6%B3%95/" itemprop="url" rel="index">
                    <span itemprop="name">算法</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="选择排序（不稳定算法）"><a href="#选择排序（不稳定算法）" class="headerlink" title="选择排序（不稳定算法）"></a>选择排序（不稳定算法）</h1><h3 id="思想：选择排序，从头至尾扫描序列，找出最小的一个元素，和第一个元素交换，接着从剩下的元素中继续这种选择和交换方式，最终得到一个有序序列。"><a href="#思想：选择排序，从头至尾扫描序列，找出最小的一个元素，和第一个元素交换，接着从剩下的元素中继续这种选择和交换方式，最终得到一个有序序列。" class="headerlink" title="思想：选择排序，从头至尾扫描序列，找出最小的一个元素，和第一个元素交换，接着从剩下的元素中继续这种选择和交换方式，最终得到一个有序序列。"></a>思想：选择排序，从头至尾扫描序列，找出最小的一个元素，和第一个元素交换，接着从剩下的元素中继续这种选择和交换方式，最终得到一个有序序列。</h3><hr>
<h4 id="实例：-12-45-40-24-15-11-12-11-，初始数组内均为有序区"><a href="#实例：-12-45-40-24-15-11-12-11-，初始数组内均为有序区" class="headerlink" title="实例：[12,45,40,24,15,11,12,11]，初始数组内均为有序区"></a>实例：[12,45,40,24,15,11,12,11]，初始数组内均为有序区</h4><h4 id="第一趟遍历：-11-40-24-15-45-12-，花扩号内为无序区"><a href="#第一趟遍历：-11-40-24-15-45-12-，花扩号内为无序区" class="headerlink" title="第一趟遍历：[{11},40,24,15,45,12]，花扩号内为无序区"></a>第一趟遍历：[{11},40,24,15,45,12]，花扩号内为无序区</h4><h4 id="第二趟遍历：-11-12-24-15-45-40"><a href="#第二趟遍历：-11-12-24-15-45-40" class="headerlink" title="第二趟遍历：[{11,12},24,15,45,40]"></a>第二趟遍历：[{11,12},24,15,45,40]</h4><h4 id="第三趟遍历-11-12-15-24-45-40"><a href="#第三趟遍历-11-12-15-24-45-40" class="headerlink" title="第三趟遍历: [{11,12,15},24,45,40]"></a>第三趟遍历: [{11,12,15},24,45,40]</h4><h4 id="第四趟遍历-11-12-15-24-45-40"><a href="#第四趟遍历-11-12-15-24-45-40" class="headerlink" title="第四趟遍历: [{11,12,15,24},45,40]"></a>第四趟遍历: [{11,12,15,24},45,40]</h4><h4 id="第五趟遍历-11-12-15-24-40-45"><a href="#第五趟遍历-11-12-15-24-40-45" class="headerlink" title="第五趟遍历: [{11,12,15,24,40},45]"></a>第五趟遍历: [{11,12,15,24,40},45]</h4><hr>
<h4 id="算法分析：时间复杂度为O-n-2"><a href="#算法分析：时间复杂度为O-n-2" class="headerlink" title="算法分析：时间复杂度为O(n^2)"></a>算法分析：时间复杂度为O(n^2)</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">selectOrder</span>(<span class="params">arr</span>)</span>&#123;</span><br><span class="line">    <span class="keyword">let</span> n=arr.length;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">let</span> i=<span class="number">0</span>;i&lt;n<span class="number">-1</span>;i++ )&#123;</span><br><span class="line">        <span class="keyword">let</span> index=i;</span><br><span class="line">        <span class="keyword">let</span> j;</span><br><span class="line">        <span class="comment">// 找出最小元素的下标</span></span><br><span class="line">        <span class="keyword">for</span>(j= i + <span class="number">1</span>;j&lt;n;j++)&#123;</span><br><span class="line">            <span class="keyword">if</span>(arr[index]&gt;arr[j])&#123;</span><br><span class="line">                index=j;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">let</span> temp=arr[i];</span><br><span class="line">        arr[i]=arr[index];</span><br><span class="line">        arr[index]=temp;</span><br><span class="line">        <span class="built_in">console</span>.log(arr.toString());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">let</span> arr=[<span class="number">45</span>,<span class="number">40</span>,<span class="number">24</span>,<span class="number">15</span>,<span class="number">11</span>,<span class="number">12</span>];</span><br><span class="line">selectOrder(arr)</span><br></pre></td></tr></table></figure>
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/Liang34/2020/03/02/fastOrder/" rel="next" title="fastOrder">
                <i class="fa fa-chevron-left"></i> fastOrder
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/Liang34/2020/03/08/closure/" rel="prev" title="closure">
                closure <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>	
  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/Liang34/images/avatar.jpg"
                alt="LiangJH" />
            
              <p class="site-author-name" itemprop="name">LiangJH</p>
              <p class="site-description motion-element" itemprop="description">前端,java</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/Liang34/archives/%7C%7C%20archive">
              
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">标签</span>
                
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#选择排序（不稳定算法）"><span class="nav-number">1.</span> <span class="nav-text">选择排序（不稳定算法）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#思想：选择排序，从头至尾扫描序列，找出最小的一个元素，和第一个元素交换，接着从剩下的元素中继续这种选择和交换方式，最终得到一个有序序列。"><span class="nav-number">1.0.1.</span> <span class="nav-text">思想：选择排序，从头至尾扫描序列，找出最小的一个元素，和第一个元素交换，接着从剩下的元素中继续这种选择和交换方式，最终得到一个有序序列。</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#实例：-12-45-40-24-15-11-12-11-，初始数组内均为有序区"><span class="nav-number">1.0.1.1.</span> <span class="nav-text">实例：[12,45,40,24,15,11,12,11]，初始数组内均为有序区</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#第一趟遍历：-11-40-24-15-45-12-，花扩号内为无序区"><span class="nav-number">1.0.1.2.</span> <span class="nav-text">第一趟遍历：[{11},40,24,15,45,12]，花扩号内为无序区</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#第二趟遍历：-11-12-24-15-45-40"><span class="nav-number">1.0.1.3.</span> <span class="nav-text">第二趟遍历：[{11,12},24,15,45,40]</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#第三趟遍历-11-12-15-24-45-40"><span class="nav-number">1.0.1.4.</span> <span class="nav-text">第三趟遍历: [{11,12,15},24,45,40]</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#第四趟遍历-11-12-15-24-45-40"><span class="nav-number">1.0.1.5.</span> <span class="nav-text">第四趟遍历: [{11,12,15,24},45,40]</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#第五趟遍历-11-12-15-24-40-45"><span class="nav-number">1.0.1.6.</span> <span class="nav-text">第五趟遍历: [{11,12,15,24,40},45]</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#算法分析：时间复杂度为O-n-2"><span class="nav-number">1.0.1.7.</span> <span class="nav-text">算法分析：时间复杂度为O(n^2)</span></a></li></ol></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">LiangJH</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/Liang34/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/Liang34/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/Liang34/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/Liang34/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/Liang34/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/Liang34/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/Liang34/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/Liang34/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/Liang34/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/Liang34/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/Liang34/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/Liang34/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/Liang34/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

<script src="/Liang34/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/Liang34/live2dw/assets/hibiki.model.json"},"display":{"position":"right","width":145,"height":315},"mobile":{"show":true,"scale":0.5},"react":{"opacityDefault":0.7,"opacityOnHover":0.8},"log":false});</script></body>
</html>
